import request from '@/utils/request'
import store from '@/store'
// 查询child列表
export function listchild(query) {
    return request({
        url: '/api/v1/childList',
        method: 'get',
        params: query
    }).then(function (res) {

        let sexOptions = store.getters.parameter.sys_user_sex; 
        let childtypeOptions = store.getters.parameter.general_user_child_type;
        
        res.data.list.forEach((item, index) => {
            // console.log(item)
            for (let key in item) {
                // console.log(key + '---' + item[key])
                 
                if (key == "sex") {
                    item[key] = getDictLabelByValue(item[key], sexOptions)
                }
                if (key == "childType") {
                    item[key] = getDictLabelByValue(item[key], childtypeOptions)
                }
                 
                
                //isFamilyOwner

            }

            res.data.list[index] = item
        });
        // console.log(res.data.list)
        return res;

    })
}
 
function getDictLabelByValue(value,dict_list){
    let dictLabel="";
    if(dict_list){
        dict_list.forEach((_item,index)=>{
            if(_item.dictValue==value){
                dictLabel= _item.dictLabel
            }
        })
        return dictLabel;
    }else{
        console.log(value);
        return ;
    }
    
}

// 查询child详细
export function getchild(childId) {
    return request({
        url: '/api/v1/child/' + childId,
        method: 'get'
    })
}


// 新增child
export function addchild(data) {
    return request({
        url: '/api/v1/child',
        method: 'post',
        data: data
    })
}

// 修改child
export function updatechild(data) {
    return request({
        url: '/api/v1/child',
        method: 'put',
        data: data
    })
}

// 删除child
export function delchild(childId) {
    return request({
        url: '/api/v1/child/' + childId,
        method: 'delete'
    })
}

// 查询child详细
export function getInheritHeight(data) {
    return request({
        url: '/api/v1/child/getInheritHeight',
        method: 'post',
        data: data
    })
}

// 查询孩子身高详情数据，如当前身高，当前遗传身高，成年身高预测，遗传增量，实测增量等
export function getHeightReportData(childId) {
    return request({
        url: '/api/v1/childInfo/height/detail/' + childId,
        method: 'get',
        
    })
}